#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define LEN 100

char *my_strstr(char *s1,char *s2)
{
    while (*s1 != '\0')
    {
        char *h = s1;
        char *n = s2;
        while (*h != '\0' && *n != '\0' && *h == *n)
        {
            h++;
            n++;
        }

        if (*n == '\0')
        {
            return (char*)s1;
        }
        s1++;
    }

    return NULL;
}

int main()
{
    char *src = (char*)malloc(LEN);
    if(NULL == src)
    {
        printf("malloc error!\n");
        exit(1);
    }
    memset(src,0,100);

    printf("请输入字符：\n");
    scanf("%s",src);
    printf("字符串为：%s\n",src);

    char *str = (char*)malloc(LEN);
    if(NULL == str)
    {
        printf("malloc error!\n");
        exit(1);
    }
    memset(str,0,100);
   
    printf("请输入需要查找的字符串：\n");
    scanf("%s",str);

    char *a = my_strstr(src,str);

    if(a != NULL){
        printf("要查找的字符串: '%s' 的初始位置为：%ld\n",str,a - src);
    }else{
        printf("没找到字符串“ '%s'\n",str);
    }
 

    free(str);

    return 0;
}